﻿using System.Linq;

namespace Solution.BusinessObject
{
    /// <summary>
    /// Provides methods for manipulating <see cref="Category"/> entity.
    /// </summary>
    public class CatergoryBO
    {
        public Category[] GetMainMenu(string languageCode = null)
        {
            var language = string.IsNullOrEmpty(languageCode)
                                    ? CommonBO.DefaultSiteLanguage
                                    : CommonBO.MasterEDM.Languages
                                          .FirstOrDefault(t => t.Code == languageCode);
            if (language == null)
            {
                return CommonBO.MasterEDM.Categories
                    .Where(t => t.Parent == null && t.Enabled == true)
                    .OrderBy(t => t.DisplayOrder)
                    .ToArray();
            }
            return CommonBO.MasterEDM.Categories
                .Where(t => t.Parent == null
                            && t.Enabled == true
                            && t.Language.Id == language.Id)
                .OrderBy(t => t.DisplayOrder)
                .ToArray();
        }
    }
}